package cn.edu.neusoft.wuguangsheng.market.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;

import cn.edu.neusoft.wuguangsheng.market.R;
import cn.edu.neusoft.wuguangsheng.market.activity.MySetActivity;
import cn.edu.neusoft.wuguangsheng.market.activity.UserAllCommentActivity;
import cn.edu.neusoft.wuguangsheng.market.bean.MyBean;
import cn.edu.neusoft.wuguangsheng.market.listener.TListener;
import cn.edu.neusoft.wuguangsheng.market.model.MyModel;

/**
 * A simple {@link Fragment} subclass.
 */
public class MyFragment extends BaseFragment {
    ImageView my_tx;
    TextView myname;
    TextView myphone;
    String uid;
    String shname;
    String phone;
    String address;
    LinearLayout linearcomment;
    Boolean up=false;
    LinearLayout my_sz;
    @Override
    void initView() {
      my_sz=(LinearLayout) view.findViewById(R.id.my_sz);
      my_tx=(ImageView) view.findViewById(R.id.my_tx);
      myname=(TextView) view.findViewById(R.id.myname);
      myphone=(TextView) view.findViewById(R.id.myphone);
        linearcomment=(LinearLayout) view.findViewById(R.id.layout_comment);
        uid=getid();
        MyModel myModel=new MyModel();
        myModel.getMyinfo(uid,tListener);
    }

    @Override
    void initEvent() {
my_sz.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent intentm=new Intent(getContext(), MySetActivity.class);
        intentm.putExtra("shname",shname);
        intentm.putExtra("phone",phone);
        intentm.putExtra("address",address);
        startActivity(intentm);
    }
    });
        linearcomment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intentc=new Intent(getContext(), UserAllCommentActivity.class);
                startActivity(intentc);
            }
        });
    }

    @Override
    void initDate() {

    }

    public MyFragment() {

    }



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        setLayout_file(R.layout.fragment_my);
        //Log.v(TAG,"onCreateView");
        return super.onCreateView(inflater,container,savedInstanceState);
    }

    TListener<MyBean> tListener=new TListener<MyBean>() {
        @Override
        public void onResponse(MyBean myBean) {
            String uname=myBean.getUname();
             phone=myBean.getPhone();
            String pic=myBean.getPic();
            shname=myBean.getShname();
            myname.setText("用户名:"+uname);
            myphone.setText("电话号码:"+phone);
            address=myBean.getAddress();
            Picasso.with(getContext()).load(pic).resize(100,100).into(my_tx);
           // Toast.makeText(getContext(),uid, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(getContext(),"???", Toast.LENGTH_SHORT).show();
        }
    };

    @Override
    public void onPause() {
        super.onPause();
        up=true;

    }

    @Override
    public void onResume() {
        super.onResume();
        if(up){
            initView();
            up=false;
        }
    }
}
